# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: AlexWMF <alexxwmf@gmail.com>

_realname=qxmpp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=1
pkgdesc="Cross-platform C++ XMPP client and server library (mingw-w64)"
arch=('any')
license=("LGPL")
url="https://github.com/qxmpp-project/qxmpp"
depends=("${MINGW_PACKAGE_PREFIX}-libtheora"
         "${MINGW_PACKAGE_PREFIX}-libvpx"
         "${MINGW_PACKAGE_PREFIX}-opus"
         "${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-speex")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc")
options=(!strip staticlibs)
source=("${_realname}-${pkgver}".tar.gz::"https://github.com/qxmpp-project/${_realname}/archive/v${pkgver}.tar.gz"
        001-fix-install.patch)
sha256sums=('3c83d7cb3e790afd62a5232956ca85378aa76b6e1d1875c921ead05b70bb0fa5'
            '9b44f5c0301ede3c83f2213edb1a158abf835aebeedcbc19806acb4ffcfa9564')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-fix-install.patch
}

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    -DBUILD_SHARED_LIBS=ON \
    -DWITH_OPUS=ON \
    -DWITH_SPEEX=ON \
    -DWITH_THEORA=ON \
    -DWITH_VPX=ON \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
  
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.LGPL ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LGPL
}
